import { loginAPI } from "@/api/user";
import { delToken, getToken, setToken } from "@/utils/storage";

export default {
  namespaced: true,
  state: {
    // token: "",
    token: getToken(),
  },
  getters: {},
  mutations: {
    setToken(state, token) {
      state.token = token; //存一份到vueX
      setToken(token); //存一份到本地存储
    },
    logOut(state) {
      state.token = "";
      delToken();
    },
  },
  actions: {
    async login(context, data) {
      const res = await loginAPI(data);
      console.log(res);
      context.commit("setToken", res.data.token);
    },
  },
  modules: {},
};
